from web.template import CompiledTemplate, ForLoop, TemplateResult

_dummy = CompiledTemplate(lambda: None, 'dummy')
join_ = _dummy._join
escape_ = _dummy._escape

def bk_twittest (twits):
    __lineoffset__ = -3
    loop = ForLoop()
    self = TemplateResult(); extend_ = self.extend
    extend_([u'<html>\n'])
    extend_([u'<head>\n'])
    extend_([u'<meta http-equiv="Content-Type" content="text/html; charset=utf-8">\n'])
    extend_([u'<title>timeline</title>\n'])
    extend_([u'</head>\n'])
    extend_([u'<body>\n'])
    extend_([u'\n'])
    extend_([u'<form method="post" action="add">\n'])
    extend_([u'<p><input type="text" name="status" /> <input type="submit" value="Add" /></p>\n'])
    extend_([u'</form>\n'])
    extend_([u'\n'])
    for twit,urls in loop.setup(twits):
        extend_([u'<li><span class="entry-content">', escape_(twit, True), u'\n'])
        for url in loop.setup(urls):
            extend_(['    ', u'<a target="_blank" href=', escape_(url, True), u'>', escape_(url, True), u'</a>\n'])
        extend_([u'</span></li>\n'])
        extend_([u'\n'])
    extend_([u'</body>\n'])
    extend_([u'</html>\n'])

    return self

bk_twittest = CompiledTemplate(bk_twittest, 'templates\\bk_twittest.html')

def formtest (form):
    __lineoffset__ = -3
    loop = ForLoop()
    self = TemplateResult(); extend_ = self.extend
    extend_([u'\n'])
    extend_([u'<form name="main" method="post"> \n'])
    if not form.valid:
        extend_([u'<p class="error">Try again, AmeriCAN:</p>\n'])
    extend_([escape_(form.render(), False), u'\n'])
    extend_([u'</form>\n'])

    return self

formtest = CompiledTemplate(formtest, 'templates\\formtest.html')

def loginform ():
    __lineoffset__ = -3
    loop = ForLoop()
    self = TemplateResult(); extend_ = self.extend
    extend_([u'<html>\n'])
    extend_([u'<head>\n'])
    extend_([u'<meta http-equiv="Content-Type" content="text/html; charset=utf-8">\n'])
    extend_([u'<title>login</title>\n'])
    extend_([u'</head>\n'])
    extend_([u'<body>\n'])
    extend_([u'\n'])
    extend_([u'<form method="post" action="/login">\n'])
    extend_([u'<p>\n'])
    extend_([u'<label class="username"> \n'])
    extend_([u'<input type="text" value="" name="name"  />\n'])
    extend_([u'</label>\n'])
    extend_([u'<label class="password"> \n'])
    extend_([u'<input type="password" value="" name="password" /> \n'])
    extend_([u'</label> \n'])
    extend_([u'<button type="submit" class="submit button">Sign in</button> \n'])
    extend_([u'</p>\n'])
    extend_([u'</form>\n'])
    extend_([u'\n'])
    extend_([u'<div>\n'])
    extend_([u'<img src="http://code.google.com/appengine/images/appengine-noborder-120x30.gif" alt="Powered by Google App Engine" />\n'])
    extend_([u'</div>\n'])
    extend_([u'\n'])
    extend_([u'</body>\n'])
    extend_([u'</html>\n'])

    return self

loginform = CompiledTemplate(loginform, 'templates\\loginform.html')

def statusupdate (message):
    __lineoffset__ = -3
    loop = ForLoop()
    self = TemplateResult(); extend_ = self.extend
    extend_([u'<html>\n'])
    extend_([u'<head>\n'])
    extend_([u'<meta http-equiv="Content-Type" content="text/html; charset=utf-8">\n'])
    extend_([u'<title>statusupdate</title>\n'])
    extend_([u'</head>\n'])
    extend_([u'<body>\n'])
    extend_([u'<li>', escape_(message, True), u'</li>\n'])
    extend_([u'<li><a href="/">back</a></li>\n'])
    extend_([u'\n'])
    extend_([u'\n'])
    extend_([u'</body>\n'])
    extend_([u'</html>\n'])

    return self

statusupdate = CompiledTemplate(statusupdate, 'templates\\statusupdate.html')

def ttstreams (twits):
    __lineoffset__ = -3
    loop = ForLoop()
    self = TemplateResult(); extend_ = self.extend
    extend_([u'<div class="one-time-stream">\n'])
    for twit,user_img,user_url in loop.setup(twits):
        extend_(['    ', u'<div class="tweet-image simple-tweet-image">\n'])
        extend_(['    ', u'    <a target="_blank" href=', escape_(user_url, True), u'><img src=', escape_(user_img, True), u' height="48" border="0" width="48"></a>\n'])
        extend_(['    ', u'</div>\n'])
        extend_(['    ', u'<div>\n'])
        for txt,url in loop.setup(twit):
            if url:
                extend_(['    ', u'<a target="_blank" href=', escape_(url, True), u'>', escape_(txt, True), u'</a>\n'])
            else:
                extend_(['    ', escape_(txt, True), u'\n'])
        extend_(['    ', u'</div>\n'])
    extend_([u'</div>\n'])

    return self

ttstreams = CompiledTemplate(ttstreams, 'templates\\ttstreams.html')

def twittest (twits):
    __lineoffset__ = -3
    loop = ForLoop()
    self = TemplateResult(); extend_ = self.extend
    extend_([u'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">\n'])
    extend_([u'<html>\n'])
    extend_([u'<head>\n'])
    extend_([u'<title>timeline</title>\n'])
    extend_([u'<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />\n'])
    extend_([u'<link rel="stylesheet" href="/static/example.css" type="text/css" />\n'])
    extend_([u'</head>\n'])
    extend_([u'\n'])
    extend_([u'<body>\n'])
    extend_([u'\n'])
    extend_([u'<script type="text/javascript" \n'])
    extend_([u'        src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js">\n'])
    extend_([u'</script>\n'])
    extend_([u'<script type="text/javascript" src="/static/test.js"></script>\n'])
    extend_([u'<script type="text/javascript" src="/static/cookie.js"></script>\n'])
    extend_([u'\n'])
    extend_([u'<form name="sendtt">\n'])
    extend_([u'<p><input type="text" name="status" id="status"/> <input class="buttonadd" type="submit" value="Add" onclick="return validateForm();"/></p>\n'])
    extend_([u'</form>\n'])
    extend_([u'\n'])
    extend_([u'<div id="TempDiv" style="visibility:hidden"></div>\n'])
    extend_([u'\n'])
    extend_([u'<form name="refreshtt">\n'])
    extend_([u'<p> <input type="hidden" name="nothing" id="nothing" /><input class="buttonrefresh" type="button" value="Refresh" onclick="return newtt();"/></p>\n'])
    extend_([u'</form>\n'])
    extend_([u'\n'])
    extend_([u'<form name="t_auth">\n'])
    extend_([u'<p> <input class="buttonauth" type="button" value="auth" onclick="return auth();"/></p>\n'])
    extend_([u'</form>\n'])
    extend_([u'\n'])
    extend_([u'<div class="auth_url">\n'])
    extend_([u'</div>\n'])
    extend_([u'<div class="stream-items">\n'])
    extend_([u'    <div class="one-time-stream">\n'])
    for twit,user_img,user_url in loop.setup(twits):
        extend_(['        ', u'<div class="tweet-image simple-tweet-image">\n'])
        extend_(['        ', u'    <a target="_blank" href=', escape_(user_url, True), u'><img src=', escape_(user_img, True), u' height="48" border="0" width="48"></a>\n'])
        extend_(['        ', u'</div>\n'])
        extend_(['        ', u'<div>\n'])
        for txt,url in loop.setup(twit):
            if url:
                extend_(['        ', u'<a target="_blank" href=', escape_(url, True), u'>', escape_(txt, True), u'</a>\n'])
            else:
                extend_(['        ', escape_(txt, True), u'\n'])
        extend_(['        ', u'</div>\n'])
    extend_([u'    </div>\n'])
    extend_([u'</div>\n'])
    extend_([u'\n'])
    extend_([u'<div>\n'])
    extend_([u'<img src="https://code.google.com/appengine/images/appengine-noborder-120x30.gif" alt="Powered by Google App Engine" />\n'])
    extend_([u'</div>      \n'])
    extend_([u'     \n'])
    extend_([u'</body>\n'])
    extend_([u'</html>\n'])

    return self

twittest = CompiledTemplate(twittest, 'templates\\twittest.html')

